package com.ufo.store.management.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

import com.ufo.store.management.ui.activity.PayMasterActivity;
import com.ufo.store.management.ui.fragment.Isszmbalv3CalenderFragment;

import java.util.ArrayList;
import java.util.List;

/**
 *  作者：taoli on 2017/2/14 0014 13:45
 *  
 */
public class Isszmbalv3CalenderViewPagerAdapter extends FragmentPagerAdapter {
    private final int mCount = PayMasterActivity.CALENDER_DAY_COUNT;
    private Isszmbalv3CalenderFragment.CalenderClickListener mCalenderClickListener = null;
    private FragmentManager mFragmentManager;
    private String mBranchNo = "";

    public Isszmbalv3CalenderViewPagerAdapter(FragmentManager fragmentManager) {
        super(fragmentManager);
        mFragmentManager = fragmentManager;
    }

    @Override
    public int getCount() {
        return mCount;
    }

    @Override
    public Fragment getItem(int position) {
        Isszmbalv3CalenderFragment fragment = new Isszmbalv3CalenderFragment();
        fragment.setBranchNo(mBranchNo);
        fragment.setPosition(position);
        fragment.setCalenderClickListener(mCalenderClickListener);
        return fragment;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return "";
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        Isszmbalv3CalenderFragment fragment = (Isszmbalv3CalenderFragment)super.instantiateItem(container, position);
        fragment.setBranchNo(mBranchNo);
        return fragment;
    }

    public void setCalenderClickListener( Isszmbalv3CalenderFragment.CalenderClickListener listener){
        mCalenderClickListener = listener;
    }

    public void setBranchNo(String branchNoStr){
        mBranchNo = branchNoStr;
        List<Fragment>  isszmbalv3CalenderFragments = mFragmentManager.getFragments();
        if(isszmbalv3CalenderFragments!=null && isszmbalv3CalenderFragments.size()!=0){
            for(int i = 0; i< isszmbalv3CalenderFragments.size(); i++){
                Isszmbalv3CalenderFragment isszmbalv3CalenderFragment =  (Isszmbalv3CalenderFragment)isszmbalv3CalenderFragments.get(i);
                if( isszmbalv3CalenderFragment !=null ){
                    isszmbalv3CalenderFragment.setBranchNo(branchNoStr);
                }
            }
        }
    }

    public void setAccountsNumber(String accountsNum, ArrayList<String> hourValueList, ArrayList<String> scanValueList){
        List<Fragment>  isszmbalv3CalenderFragments = mFragmentManager.getFragments();
        if(isszmbalv3CalenderFragments!=null && isszmbalv3CalenderFragments.size()!=0){
            for(int i = 0; i< isszmbalv3CalenderFragments.size(); i++){
                Isszmbalv3CalenderFragment isszmbalv3CalenderFragment =  (Isszmbalv3CalenderFragment)isszmbalv3CalenderFragments.get(i);
                if( isszmbalv3CalenderFragment !=null && isszmbalv3CalenderFragment.getUserVisibleHint()){
                    isszmbalv3CalenderFragment.setAccountsNumber(accountsNum,hourValueList,scanValueList);
                }
            }
        }
    }

    public void setRefresh(){
        List<Fragment>  isszmbalv3CalenderFragments = mFragmentManager.getFragments();
        if(isszmbalv3CalenderFragments!=null && isszmbalv3CalenderFragments.size()!=0){
            for(int i = 0; i< isszmbalv3CalenderFragments.size(); i++){
                Isszmbalv3CalenderFragment isszmbalv3CalenderFragment =  (Isszmbalv3CalenderFragment)isszmbalv3CalenderFragments.get(i);
                if( isszmbalv3CalenderFragment !=null && isszmbalv3CalenderFragment.getUserVisibleHint()){
                    isszmbalv3CalenderFragment.setRefresh();
                }
            }
        }
    }
}

